package com.fpmsa.officeweb.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.fpmsa.officeweb.dao.JobMapper;
import com.fpmsa.officeweb.model.Job;
import com.fpmsa.officeweb.service.IJobService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 招聘信息表 服务实现类
 * </p>
 *
 * @author huangyuehong123
 * @since 2018-07-01
 */
@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements IJobService {

    @Override
    public List<Map<String, Object>> getJobList(Page<Job> page, String condition, String orderByField, boolean asc) {
        return this.baseMapper.getJobList(page,condition,orderByField,asc);
    }

    // 格式化招聘岗位时间相关字段
    public List<Map<String,Object>> formatDate(List<Job> jobList,String formatStr){
        List<Map<String,Object>> mapList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat(formatStr);

        for (Job job : jobList){
            Map<String,Object> map = new HashMap<>();
            map.put("id",job.getId());
            map.put("name",job.getName());
            map.put("count",job.getCount());
            map.put("workYear",job.getWorkYear());
            map.put("education",job.getEducation());
            map.put("workplace",job.getWorkplace());
            map.put("salary",job.getSalary());
            map.put("duty",job.getDuty());
            map.put("requirement",job.getRequirement());
            map.put("welfare",job.getWelfare());
            map.put("createTime",sdf.format(job.getCreateTime()));
            map.put("updateTime",sdf.format(job.getUpdateTime()));
            map.put("isDel",job.getIsDel());

            mapList.add(map);
        }
        return mapList;
    }
}
